package factory.impl;

import config.LoggerConfig;
import factory.LoggerFactory;
import service.impl.ConsoleLogger;
import service.impl.DatabaseLogger;
import service.impl.FileLogger;
import service.Logger;
/**
 * 配置化的日志工厂 - 演示更复杂的工厂方法
 */
public class ConfigurableLoggerFactory extends LoggerFactory {
    private LoggerConfig config;
    
    public ConfigurableLoggerFactory(LoggerConfig config) {
        this.config = config;
    }
    
    @Override
    public Logger createLogger() {
        Logger logger;
        
        switch (config.getType()) {
            case FILE:
                logger = new FileLogger(config.getFilePath());
                break;
            case DATABASE:
                logger = new DatabaseLogger(config.getConnectionString());
                break;
            case CONSOLE:
            default:
                logger = new ConsoleLogger();
                break;
        }
        
        logger.setLevel(config.getLevel());
        return logger;
    }
}



